package com.jingogo.controller;

import com.jingogo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.constraints.NotNull;
import com.jingogo.service.MetalRecyclingService;

@Slf4j
@RestController
@RequestMapping("/metalRecycling")
@Tag(name = "金属回收", description = "金属回收相关接口")
public class MetalRecyclingController {

    @Autowired
    private MetalRecyclingService metalRecyclingService;

    @PostMapping("/createOrder")
    @Operation(summary = "创建回收订单", description = "用户创建金属回收订单")
    @PreAuthorize("hasRole('USER')")
    public Result<String> createRecyclingOrder(@RequestParam @NotNull(message = "用户ID不能为空") Long userId,
                                               @RequestParam @NotNull(message = "回收信息不能为空") String recyclingInfo) {
        metalRecyclingService.createRecyclingOrder(userId, recyclingInfo);
        return Result.success("回收订单创建成功");
    }

    @PutMapping("/updateStatus")
    @Operation(summary = "更新回收订单状态", description = "更新金属回收订单状态")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> updateRecyclingOrderStatus(@RequestParam @NotNull(message = "订单ID不能为空") Long orderId,
                                                     @RequestParam @NotNull(message = "订单状态不能为空") String status) {
        metalRecyclingService.updateRecyclingOrderStatus(orderId, status);
        return Result.success("订单状态更新成功");
    }
}

